package com.housekeeping.housekeeping.advertisingmanagement.service.impl;/*
 * @author  pyh
 * @date  2021/1/22 0022 下午 9:19
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.dao.ProductDao;
import com.housekeeping.housekeeping.advertisingmanagement.dao.impl.ProductDaoImpl;
import com.housekeeping.housekeeping.advertisingmanagement.entity.Product;
import com.housekeeping.housekeeping.advertisingmanagement.service.ProductService;
import com.housekeeping.housekeeping.advertisingmanagement.utils.Page;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();

    @Override
    public int saveAdMessages(Product product) {
        int count = productDao.insert(product);
        return count;
    }
    //分页查询有问题
    @Override
    public Page<Product> list(int page, int size) throws SQLException {
        List<Product> products = productDao.selectByPage((page - 1) * size, size);
        //查询总页数
        int counts = productDao.selectCount();
        Page<Product> pageBean = new Page<>(page, size, counts);
        pageBean.setData(products);
        return pageBean;
    }

    @Override
    public void add(Product product) {
        productDao.insert(product);
    }

    @Override
    public int del(int id) {
        int del = productDao.delete(id);
        return del;
    }

    @Override
    public Product update(int id) {
        Product update = productDao.update(id);
        return update;
    }
}
